package com.clearance.mine_clearance.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.clearance.mine_clearance.config.Constants;
import com.clearance.mine_clearance.entry.ButtenConfig;
import com.clearance.mine_clearance.entry.Result;
import com.clearance.mine_clearance.mapper.ButtenConfigMapper;
import com.clearance.mine_clearance.untils.RedisUntils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@CrossOrigin("*")
@RequestMapping("/mine/buttenConfig")
public class ButtenConfigController {

    @Autowired
    private ButtenConfigMapper buttenConfigMapper;

    @GetMapping("/getButten")
    public Result getButten(){
        List<ButtenConfig> buttenConfigList = buttenConfigMapper.selectList(new LambdaQueryWrapper<>());
        return new Result().success(buttenConfigList);
    }

    @PostMapping("/updateButten")
    public Result updateButten(@RequestBody ButtenConfig buttenConfig){
        buttenConfigMapper.updateById(buttenConfig);
        List<ButtenConfig> buttenConfigList = buttenConfigMapper.selectList(new LambdaQueryWrapper<>());
        RedisUntils.setValue(Constants.buttonConfig, JSON.toJSONString(buttenConfigList));
        return new Result().success(buttenConfig);
    }
}




















